package kata.chop;

public class RecursiveBinaryChop extends BinaryChop {

	@Override
	protected int chop() {
		if (startPosition > endPosition)
			return NOT_FOUND;
		computeMiddle();
		if (found())
			return middlePosition;
		if (searchTheLeftHalf()) {
			endPosition = middlePosition - 1;
			return chop();
		}
		if (searchTheRightHalf()) {
			startPosition = middlePosition + 1;
			return chop();
		}
		return NOT_FOUND;
	}

}
